package com.example.service.impl;

import com.example.dao.Emp1Mapper;
import com.example.pojo.Emp1;
import com.example.pojo.PageBean;
import com.example.service.Emp1Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Service
public class Emp1ServiceImpl implements Emp1Service {
    @Autowired
    Emp1Mapper emp1Mapper;
    //条件分页查询
    @Override
    public PageBean page(Integer page, Integer pagesize, String name, Short gender, LocalDate begin, LocalDate end) {
        //设置分页参数
        PageHelper.startPage(page,pagesize);
        //执行查询
        List<Emp1> emp1List = emp1Mapper.list(name, gender, begin, end);
        //强转为page集合对象
        Page<Emp1> p= (Page<Emp1>) emp1List;
        //封装成PageBean对象
        PageBean pageBean=new PageBean(p.getTotal(),p.getResult());
        return pageBean;
    }
    //批量删除
    @Override
    public void deleteById(List<Integer> ids) {
        emp1Mapper.deleteById(ids);
    }
    //根据id查询回显数据
    @Override
    public Emp1 selectById(Integer id) {
        Emp1 emp1= emp1Mapper.selectById(id);
        return emp1;
    }
    //修改数据
    @Override
    public void update(Emp1 emp1) {
        emp1.setUpdateTime(LocalDateTime.now());
        emp1Mapper.update(emp1);
    }
    //添加数据
    @Override
    public void add(Emp1 emp1) {
        emp1.setUpdateTime(LocalDateTime.now());
        emp1.setCreateTime(LocalDateTime.now());
        emp1Mapper.insert(emp1);
    }
    //根据id查询

}
